package com.bjpowernode.springboot.web;

import com.bjpowernode.springboot.model.Student;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @DATE 2021--11--28 22:59
 */
@RestController
public class IndexController {


   @RequestMapping(value = "/student")
    public Object student(Integer id,Integer age){
       Student student = new Student();
       student.setId(id);
       student.setAge(age);
       return student;
   }

//   @RequestMapping(value = "/student/detail/{id}/{age}")
   @GetMapping(value = "/student/detail/{id}/{age}")
   public Object student1(@PathVariable("id") Integer id,
                          @PathVariable("age") Integer age){
      Map<String,Object> retMap = new HashMap<>();

      retMap.put("id",id);
      retMap.put("age",age);
      return retMap;
   }

//   @RequestMapping(value = "/student/detail/{id}/{status}")
   @DeleteMapping(value = "/student/detail/{id}/{status}")
   public Object student2(@PathVariable("id") Integer id,
                          @PathVariable("status") Integer status){
      Map<String,Object> retMap = new HashMap<>();

      retMap.put("id",id);
      retMap.put("status",status);
      return retMap;
   } //以上代码出现请求路径不清楚，通常RESTful风格中方法的请求通常为增删改查的请求方式

   @DeleteMapping(value = "/student/{id}/detail/{city}")
   public Object student3(@PathVariable("id") Integer id,
                          @PathVariable("city") Integer city){
      Map<String,Object> retMap = new HashMap<>();

      retMap.put("id",id);
      retMap.put("city",city);
      return retMap;
   }
   @PostMapping(value = "/student/{id}")
   public String addStudent(@PathVariable("id") Integer id){
      return "add student ID:" + id;
   }
   @PutMapping(value = "/student/{id}")
   public String updateStudent(@PathVariable("id") Integer id){
      return "update Student ID:" + id;
   }
}
